define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'express/withdraw/index' + location.search,
                    add_url: 'express/withdraw/add',
                    edit_url: '',
                    del_url: 'express/withdraw/del',
                    multi_url: 'express/withdraw/multi',
                    import_url: 'express/withdraw/import',
                    table: 'express_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'express_id', title: __('Express_id')},
                        {field: 'expressuser.username', title: __('快递员名称'), operate: 'LIKE'},
                        {field: 'num', title: __('Num'), operate:'BETWEEN'},
                        {field: 'charge', title: __('Charge'), operate:'BETWEEN'},
                        {field: 'real_num', title: __('Real_num'), operate:'BETWEEN'},
                        {field: 'with_type', title: __('With_type'), searchList: {"wechat":__('With_type wechat'),"alipay":__('With_type alipay'),"bank":__('With_type bank')}, formatter: Table.api.formatter.normal},
                        {field: 'payaccount.username', title: __('Payaccount.username'), operate: 'LIKE'},
                        {field: 'payaccount.mobile', title: __('Payaccount.mobile'), operate: 'LIKE'},
                        {field: 'payaccount.bankName', title: __('Payaccount.bankname'), operate: 'LIKE'},
                        {field: 'payaccount.cardCode', title: __('Payaccount.cardcode'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [ {
                                name: 'agree',
                                title: __('同意提现申请'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa fa-check',
                                text: '同意',
                                confirm: '确认点击同意，通过提现申请？',
                                url: 'express/withdraw/agree',
                                visible: function(row) {
                                    // 审核:0=提交资质,1=提交店铺,2=提交审核,3=通过,4=未通过
                                    if (row.status == 0) {
                                        return true;
                                    }
                                },
                                success: function(data, ret) {
                                    table.bootstrapTable('refresh');
                                    return false;
                                },
                                error: function(data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            }, {
                                name: 'refuse',
                                title: __('拒绝提现申请'),
                                classname: 'btn btn-xs btn-danger btn-dialog',
                                icon: 'fa fa-times',
                                text: '拒绝',
                                url: 'express/withdraw/refuse',
                                visible: function(row) {
                                    if (row.status == 0) {
                                        return true;
                                    }
                                },
                                extend: 'data-area=["500px","270px"]'
                            }],
                            formatter: Table.api.formatter.operate,
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
